//Date.cpp
#include <iostream>
#include "Date.h"
using namespace std;

Date::Date(int y, int m, int d) {
    if (y < 1921) {//目前window系统最小的年份为1921年
        cout << "请输入1921年及其以后的日期" << endl;
        year = 1921;
        m = 1;
        d = 1;
    } else if (m < 1 || m > 12 || d < 1 || d > 31) {
        cout << "输入的日期不合法";
        year = y;
        m = (m < 1) ? 1 : 12;
        d = 1;
    } else {
        year = y;
        month = m;
        day = d;
    }
}

Date::Date(const Date& date) {
    this->year = date.year;
    this->month = date.month;
    this->day = date.day;
}

Date::~Date() {

}

Date& Date::operator=(const Date& date) {
    if (this != &date) {
        this->year = date.year;
        this->month = date.month;
        this->day = date.day;
    }
    return *this;
}

ostream& operator<<(ostream& out, const Date& date) {
    out << date.year << "年";
    if (date.month < 10) {
        out << "0" << date.month << "月";
    } else {
        out << date.month << "月";
    }
    if (date.day < 10) {
        out << "0" << date.day << "日";
    } else {
        out << date.day << "日";
    }
    return out;
}